#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/2/19


name = "alex"
# 首字母大写
print(name.capitalize())
# 大写转小写
print(name.casefold())

print(8 * "*")

result = name.center(20, "*")
print(result)

name1 = "gfdhgsdgldsfhgk;shgk;hgrehiehiuahghafdhg;adhgagh"
# g出现的次数
result = name1.count("g")
# 在子序列中出现的次数
result1 = name.count("g", 0, 10)
# 转码
name.encode("gbk")

# 是否以x结尾
name.endswith("x")
# 是否以a开头
name.startswith("a")

# tab转空格(默认一个tab转8个空格)
name.expandtabs()
# 获取某个自序列在字符串中的位置，找不到会返回-1
name.find("a", 0, 3)
# 同上 但是找不到会报异常
name.index("a")

name3 = "{0} as {1}"
# 字符串拼接
result3 = name3.format("alex", "sb")
# print(result3)


li = ["s", "b", "a", "l", "e", "x"]
# 把序列中的元素按照某种形式连接起来
result4 = "_".join(li)
# 大小写反转
name.swapcase()
# 每个单词的首字母大写
name.title()
print(name.swapcase())
